<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 *
 */
class Dianxiaomi extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Dnsrecord;
    }
    /**
     * 获取可访问的广告主列表
     */
    public function dianxiaomi()
    {
        $url = 'https://www.dianxiaomi.com/package/searchPackage.htm?pageNo=1&pageSize=100&state=&shopId=-1&history=&searchType=trackNumber&content=AG951212675CN&isVoided=-1&isRemoved=-1&commitPlatform=&platform=&isGreen=0&isYellow=0&isOrange=0&isRed=0&isViolet=0&isBlue=0&cornflowerBlue=0&pink=0&teal=0&turquoise=0&unmarked=0&isSearch=1&isFree=-1&isBatch=-1&isOversea=-1&forbiddenStatus=-1&forbiddenReason=0&orderField=order_create_time&behindTrack=-1&storageId=0&timeOut=0&orderSearchType=1';
        $result = $this->geturl($url);
        dump($result);
        die;
//        $result = $this->posturl($url,$data,$AccessToken);
        if (!empty($result)) {
            $result = json_decode($result,true);
            $this->success('返回数据', $result);
        } else {
            $this->success('暂无接口调用');
        }
    }

    function geturl($url,$AccessToken=null){
        $headerArray =array("Content-type:text/html;charset=UTF-8;","Accept: text/html, */*; q=0.01");
//        if(!empty($AccessToken)){
            $AccessToken1 = 'Set-Cookie:JSESSIONID=F6D8660D18C257B863E78E85E8133E70; Path=/; Secure; HttpOnly';
            $AccessToken2 = 'Set-Cookie:rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Sun, 28-Nov-2021 10:11:52 GMT; SameSite=lax';
            $headerArray[] = $AccessToken1;
            $headerArray[] = $AccessToken2;
//        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    function posturl($url,$data = array(),$AccessToken=null){
        $data = (is_array($data)) ? json_encode($data,JSON_UNESCAPED_UNICODE) : $data;
        $headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json");
        if(!empty($AccessToken)){
            $headerArray[] = $AccessToken;
        }
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
}
